
var drp_options = {
  opens: (App.isRTL() ? 'left' : 'right'),
  startDate: moment().subtract('days', 29).format('YYYY/MM/DD'),
  endDate: moment(),
  minDate: '01/01/2012',
  maxDate: '12/31/2014',
  dateLimit: {
      days: 60
  },
  showDropdowns: true,
  showWeekNumbers: true,
  timePicker: false,
  timePickerIncrement: 1,
  timePicker12Hour: true,
  ranges: {
      '今天': [moment(), moment()],
      '昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
      '过去7天': [moment().subtract('days', 6), moment()],
      '过去30天': [moment().subtract('days', 29), moment()],
      '本月': [moment().startOf('month'), moment().endOf('month')],
      '上个月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
  },
  buttonClasses: ['btn'],
  applyClass: 'green',
  cancelClass: 'default',
  format: 'MM/DD/YYYY',
  separator: ' to ',
  locale: {
      applyLabel: '确定',
      cancelLable:'取消',
      fromLabel: '开始',
      toLabel: '结束',
      customRangeLabel: '自定义范围',
      daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
      monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
      firstDay: 0
  }
}

var drp_callback = function (start, end) {
        $('#reportrange span').html(start.format('YYYY/MM/DD') + ' - ' + end.format('YYYY/MM/DD'));
    }

var previousPoint = null, previousLabel = null;

$.fn.UseTooltip = function () {
    $(this).bind("plothover", function (event, pos, item) {
        if (item) {
            if ((previousLabel != item.series.label) || (previousPoint != item.dataIndex)) {
                previousPoint = item.dataIndex;
                previousLabel = item.series.label;
                $("#tooltip").remove();

                var x = item.datapoint[0];
                var y = item.datapoint[1];

                var color = item.series.color;

                console.log(item.series.xaxis.ticks[x].label);               

                showTooltip(item.pageX,
                item.pageY,
                color,
                item.series.xaxis.ticks[x].label + " : <strong>" + y + "</strong>");
            }
        } else {
            $("#tooltip").remove();
            previousPoint = null;
        }
    });
};


function showTooltip(x, y, color, contents) {
    $('<div id="tooltip">' + contents + '</div>').css({
        position: 'absolute',
        display: 'none',
        top: y - 40,
        left: x - 120,
        border: '2px solid ' + color,
        padding: '3px',
        'font-size': '9px',
        'border-radius': '5px',
        'background-color': '#fff',
        'font-family': 'Verdana, Arial, Helvetica, Tahoma, sans-serif',
        opacity: 0.9
    }).appendTo("body").fadeIn(200);
}


